package com.tledu.student_manager.utils;

import com.tledu.student_manager.exception.CustomException;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBUtil {
    public static Connection getConnection() throws CustomException {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            // 2. 创建链接
            return DriverManager.getConnection(
                    "jdbc:mysql://localhost:3306/web18_practice",
                    "root",
                    "root"
            );
        } catch (ClassNotFoundException | SQLException e) {
            e.printStackTrace();
            throw new CustomException("数据库连接获取错误");
        }
    }
}
